home *** CD-ROM | disk | FTP | other *** search
/ Motor Sport Digital Archive Collection 1960s / Motor Sport Digital Archive Collection 1960s.iso / main.swf / scripts / com / glenpike / loader / TextLoader.as
Encoding:
Text File  |  2008-05-21  |  2.0 KB  |  72 lines

  1. package com.glenpike.loader
  2. {
  3.    import flash.events.ErrorEvent;
  4.    import flash.events.Event;
  5.    import flash.events.EventDispatcher;
  6.    import flash.events.HTTPStatusEvent;
  7.    import flash.events.IOErrorEvent;
  8.    import flash.events.SecurityErrorEvent;
  9.    import flash.net.URLLoader;
  10.    import flash.net.URLLoaderDataFormat;
  11.    import flash.net.URLRequest;
  12.    
  13.    public class TextLoader extends EventDispatcher
  14.    {
  15.       private var _text:String;
  16.       
  17.       private var _ldr:URLLoader;
  18.       
  19.       public function TextLoader()
  20.       {
  21.          super();
  22.          _init();
  23.       }
  24.       
  25.       public function loadFile(param1:String) : void
  26.       {
  27.          var _loc2_:URLRequest = null;
  28.          _text = null;
  29.          _loc2_ = new URLRequest(param1);
  30.          _ldr.load(_loc2_);
  31.       }
  32.       
  33.       private function onIOError(param1:IOErrorEvent) : void
  34.       {
  35.          trace("IOError " + param1.text);
  36.          dispatchEvent(new ErrorEvent(ErrorEvent.ERROR,false,false,"Failed to load file"));
  37.       }
  38.       
  39.       private function onSecurityError(param1:SecurityErrorEvent) : void
  40.       {
  41.          trace("SecurityError " + param1.text);
  42.          dispatchEvent(new ErrorEvent(ErrorEvent.ERROR,false,false,"Not allowed to laod file"));
  43.       }
  44.       
  45.       private function onHTTPStatusEvent(param1:HTTPStatusEvent) : void
  46.       {
  47.          trace("HTTPStatus " + param1.status);
  48.       }
  49.       
  50.       public function get text() : String
  51.       {
  52.          return _text;
  53.       }
  54.       
  55.       private function onDataLoad(param1:Event) : void
  56.       {
  57.          _text = param1.target.data;
  58.          trace("loaded " + text.substr(0,20));
  59.          dispatchEvent(new Event(Event.COMPLETE));
  60.       }
  61.       
  62.       private function _init() : void
  63.       {
  64.          _ldr = new URLLoader();
  65.          _ldr.dataFormat = URLLoaderDataFormat.TEXT;
  66.          _ldr.addEventListener(Event.COMPLETE,onDataLoad,false,0,true);
  67.          _ldr.addEventListener(IOErrorEvent.IO_ERROR,onIOError,false,0,true);
  68.       }
  69.    }
  70. }
  71.  
  72.